﻿namespace Microsoft.VisualStudio.TextTemplating.CommandLine
{
    using System;
    using System.IO;
    using System.Reflection;

    internal class AssemblyQuery : MarshalByRefObject
    {
        public string GetAssemblyLocation(string assemblyName)
        {
            if (string.IsNullOrEmpty(assemblyName))
            {
                throw new ArgumentNullException(assemblyName);
            }
            Assembly assembly = null;
            try
            {                
                assembly = Assembly.Load(assemblyName);
            }
            catch (ArgumentNullException)
            {
                return null;
            }
            catch (ArgumentException)
            {
                return null;
            }
            catch (FileNotFoundException)
            {
                return null;
            }
            catch (FileLoadException)
            {
                return null;
            }
            catch (BadImageFormatException)
            {
                return null;
            }
            if (assembly != null)
            {
                return assembly.Location;
            }
            return null;
        }
    }
}

